package 剑指offer;

import java.util.Stack;

public class _09用两个栈实现队列 {
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public _09用两个栈实现队列() {
        stack1 = new Stack<Integer>();
        stack2 = new Stack<Integer>();
    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {
        if(!stack2.isEmpty()) {
            return stack2.pop();
        }else{
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }
            if(!stack2.isEmpty()) {
                return stack2.pop();
            }
            return -1;
        }
    }
}
